// 请求接口封装
import base from '../api/base.js'

// 请求头部
const header = {
    contentType : "application/json;charsetset=UTF-8"
}

// 封装request 
const request = (options) => {
    return new Promise((resolve, reject) => {
        uni.request({
            method: options.method || 'GET',
            url: base + options.url || '',
            data: options.data || {},
            header: options.header || header,
            dataType: 'json',
            success: ((res) => {
                console.log("查询结果--------------------",res)
                // 根据实际接口返回的来进行判断
                if (res.data.code === 403 || res.data.code === 401) {
                    // 错误处理，返回登录页
                    uni.reLaunch({
                        url: '/pages/login/index'
                    })
                } else if (res.data.code === 200) {
                    resolve(res.data)
                }
            }),
            fail: ((err) => {
                reject(err)
            })
        })
    })
}

export default request
